﻿Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.Collections.Generic
Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports Microsoft.Practices.EnterpriseLibrary.ExceptionHandling
Imports System.Data.Common

Public Class Shifts
#Region "Constants"
    Protected Const _Shift As String = "Shift"
    Protected Const _ShiftID As String = "ShiftID"
#End Region
#Region "private"
    Private intShiftID As Integer = 0
    Private strShift As String = String.Empty
    Private Shared el As New errorLog
#End Region
#Region "Public"
    Public Property ShiftID() As Integer
        Get
            Return intShiftID
        End Get
        Set(ByVal value As Integer)
            intShiftID = value
        End Set
    End Property
    Public Property Shift() As String
        Get
            Return strShift
        End Get
        Set(ByVal value As String)
            strShift = value
        End Set
    End Property
#End Region
    Public Function GetShiftByShiftID() As Boolean
        Dim blFound As Boolean = False
        Dim db As Database = DbStoreFactory.CreateDatabase
        Dim cmd As DbCommand = DirectCast(Nothing, DbCommand)
        Dim reader As IDataReader = Nothing

        Try
            cmd = db.GetStoredProcCommand("GetShiftByShiftID")
            db.DiscoverParameters(cmd)
            cmd.Parameters("@intShiftID").Value = intShiftID

            reader = db.ExecuteReader(cmd)

            Do While (reader.Read)
                intShiftID = Convert.ToInt16(reader(_ShiftID))
                strShift = reader(_Shift).ToString
                blFound = True
            Loop

        Catch ex As Exception
            el.CatchError(ex)
        Finally
            If Not (cmd Is Nothing) Then
                cmd.Dispose()
            End If
            If Not (reader Is Nothing) Then
                reader.Close()
            End If
        End Try
        Return blFound
    End Function

    Public Function GetAllShifts() As DataTable
        Dim db As Database = DbStoreFactory.CreateDatabase
        Dim cmd As DbCommand = DirectCast(Nothing, DbCommand)
        Dim reader As IDataReader = Nothing

        Dim dt As DataTable = New DataTable()
        dt.Columns.Add(_ShiftID, GetType(Integer))
        dt.Columns.Add(_Shift, GetType(String))

        Try
            cmd = db.GetStoredProcCommand("GetAllShifts")
            db.DiscoverParameters(cmd)
            reader = db.ExecuteReader(cmd)

            Dim dr As DataRow

            Do While (reader.Read)
                intShiftID = Convert.ToInt16(reader(_ShiftID))
                strShift = reader(_Shift).ToString

                dr = dt.NewRow()
                dr(_ShiftID) = intShiftID
                dr(_Shift) = strShift
                dt.Rows.Add(dr)
            Loop

        Catch ex As Exception
            el.CatchError(ex)
        Finally
            If Not (cmd Is Nothing) Then
                cmd.Dispose()
            End If
            If Not (reader Is Nothing) Then
                reader.Close()
            End If
        End Try
        Return dt
    End Function
End Class
